<!-- 科室-确认取走 -->
<template>
	<ListLayout>
		<!-- 附件 -->
		<AttachmentCard ref="AttachmentCard"></AttachmentCard>
		<!-- 设备接收确认 -->
		<ServiceDeviceCard :defaultData="data" ref="ServiceDeviceCard" :where="'department'"></ServiceDeviceCard>
		<!-- 评价 -->
		<EvaluationCard ref="EvaluationCard"></EvaluationCard>
		<!-- 签名 -->
		<SignCard ref="SignCard"></SignCard>
		<template #footer>
			<HButtonGroup @leftClick="leftClick" @rightClick="rightClick">
				<template #left>
					取消
				</template>
				<template #right>
					确认
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>
</template>

<script>
	import ListLayout from '@/components/layout/listLayout.vue'

	import AttachmentCard from '@/components/card/attachment.vue'
	import EvaluationCard from '@/components/card/evaluation.vue'
	import ServiceDeviceCard from '@/components/card/sendRepair/factory/info/serviceDevice.vue'

	import SignCard from '@/components/card/sign.vue'

	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import ReapirApi from '@/apis/repair.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	import { attachmentFormatter } from '@/common/submitFormatter.js'
	import { mathSum } from '@/filter/index.js'
	export default {
		components: {
			ListLayout,
			ServiceDeviceCard,
			AttachmentCard,
			SignCard,
			EvaluationCard,
			HButtonGroup,
		},
		data() {
			return {
				routerParams: {
					id: ''
				},
				data: null
			}
		},
		onLoad(query) {
			const {
				id
			} = query
			this.$set(this.routerParams, 'id', id)
			this.initData()
		},
		methods: {
			async initData() {
				let res = await ReapirApi.common.getDetail(this.routerParams.id)
				if (res.code == 0) {
					this.data = res.body
				}
			},
			leftClick() {
				wx.navigateBack()
			},
			// 确认
			async rightClick() {

				let {
					AttachmentCard,
					ServiceDeviceCard,
					EvaluationCard,
					SignCard
				} = this.$refs
				let {
					user,
					phone,
					situation,
					appearance,
					state,
					test,
					voiceReturn,
					voiceType,
					voiceNo,
					settlementMethod
				} = ServiceDeviceCard?.$data.formData || {}
				let attachment = AttachmentCard.$data.attachment
				let {
					manner,
					quality,
					responseTimeliness,
					text
				} = EvaluationCard?.$data.evaluationData || {}

				SignCard.upSign(async (file) => {
					let params = {
						// 送修id
						repairId: this.routerParams.id,
						// 维修结果（1.已完成 2.完成部分 3.未完成）
						repairResult: situation || '',
						// 结算方式
						settlementMethod: settlementMethod || '',
						// 设备状态外观
						deviceState: appearance || '',
						// 设备数据状态
						deviceData: state || '',
						// 是否有发票（0.否，1.是）
						invoiceFlag: voiceReturn || '',
						// 发票类型
						invoiceType: voiceType || '',
						// 发票号
						invoiceNum: voiceNo || '',
						// 发票附件
						invoiceEnclosure: '',
						// 是否有测试报告（0.否，1.是）
						testReportFlag: test || '',
						// 测试报告附件
						testReportEnclosure: '',
						// 附件
						enclosure: attachmentFormatter(attachment),
						// 接收人/取走人
						receiveUser: user || '',
						// 接收人电话/取走人电话
						receivePhone: phone || '',
						// 签名人
						signUser: '',
						// 签名地址
						signAddress: file?.url || '',
						// 服务态度
						serviceAttitude: manner || '',
						// 服务质量
						serviceQuality: quality || '',
						// 响应时效
						responsePrescription: responseTimeliness || '',
						// 意见与建议
						commentSuggestion: text || '',
						// 评价结果
						evaluateResult: mathSum([manner, quality, responseTimeliness])
					}
					await ReapirApi.department.confirmService(params)
					wx.showToast({
						title: '取走成功!',
						icon: 'success',
						complete() {
							wx.redirectTo({
								url: SendRepairRouterConfig.Department.Index
							})
						}
					})
				})
			},
		}

	}
</script>

<style>
</style>
